package com.thwj.project.secCheck;

import cn.binarywang.wx.miniapp.api.WxMaService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SecCheckUtil {


    @Autowired
    WxMaService wxMaService;

    /***
     * 文字检查 是否 安全
     * @param content
     * @return
     */
    public boolean checkContentSecurity(String content) {
        try {
            boolean checkContentSecurity = wxMaService.getSecCheckService().checkMessage(content);
            return checkContentSecurity;
        } catch (WxErrorException e) {
            if(e.getError().getErrorCode() == 87014) {
                return false;
            }
            log.error("文字审核服务异常 E: {}", e);
            return false;
        }
    }
    /***
     * 图片检查 是否 安全
     * @param picUrl
     * @return
     */
    public boolean checkImageSecurity(String picUrl) {
        try {
            boolean checkPicSecurity = wxMaService.getSecCheckService().checkImage(picUrl);
            return checkPicSecurity;
        } catch (WxErrorException e) {
            if(e.getError().getErrorCode() == 87014) {
                return false;
            }
            log.error("图片审核服务异常 E: {}", e);
            return false;
        }
    }

}
